import React from 'react';
import E from 'wangeditor';
import Editor from 'wangeditor';
import styles from './index.less';

export default ({editorRef}: { editorRef: any }) => {
   const divRef = React.useRef<any>();
   let editor: Editor | null = null;
   React.useImperativeHandle(editorRef, () => {
      return {
         onSubmit: () => {
            return editor?.txt?.html();
         },
         setValue: (data: string | undefined) => {
            editor?.txt?.html(data);
         }
      };
   });

   React.useEffect(() => {
      editor = new E(divRef.current);
      editor.config.height = 500;
      editor.config.pasteFilterStyle = false;
      editor.config.excludeMenus = [
         'todo',
         'video',
         'code'
      ];
      editor.create();
   }, []);

   return <div ref={divRef} className={styles.layout} />;
}
